package band.wukong.practice.javase.core.io;

import java.io.RandomAccessFile;

/**
 * Desc:
 * Author: sunjs
 * Date: 2009-11-20 13:31:55
 */
public class TestRandomAccessFile {
    private static final String FILE_IN = "D:\\WorkZone\\lab\\TestJava\\src\\com\\jsun\\javase\\corepackage\\io\\doc\\random.txt";

    private static final String MODE_READONLY = "r";
    private static final String MODE_READ_WRITE = "rw";

    public static void main(String[] args) throws Exception {
        RandomAccessFile rf = new RandomAccessFile(FILE_IN, MODE_READ_WRITE);
        for (int i = 0; i < 10; i++) {
            rf.writeLong(i * 1000);
        }

        rf.seek(5 * 8);   //从文件开头开始，跳过第5个long型数据，接下来写第6个long数据
        rf.writeLong(1234);

        rf.seek(0); //把读写指针定位到文件开头
        for (int i = 0; i < 10; i++) {
            System.out.println("Value" + i + ": " + rf.readLong());
        }

        rf.close();
    }
}
